<?php

namespace App\Http\Controllers;

use App\Http\Resources\PoolResource;
use App\Models\Pool;
use App\Models\PoolUp;
use Illuminate\Http\Request;

class PoolController extends Controller
{
    // 点赞
    public function poolUp()
    {
        $user = auth()->user();
       if (!PoolUp::where('user_id', $user->id)->exists() && Pool::find(request('id'))) {
           PoolUp::create([
               'user_id' => $user->id,
               'pool_id' => request('id')
           ]);

           Pool::where('id', request('id'))->increment('up');
       }


        return $this->array([
            'up' => Pool::where('id', request('id'))->value('up')
        ]);
    }

    // 矿池列表
    public function pool(Request $request)
    {
        $list = Pool::where('status', 1)->get();
        return PoolResource::collection($list);
    }
}
